<template>
    <div class="home">
    <el-container style="position: relative">
      <!-- 侧边栏 -->
      <el-aside width="auto">
        <div class="logo"></div>
         <el-scrollbar style="height:100%">
          <el-menu
          :router="true"
          :unique-opened=true
          :collapse="isCollapse"
          class="el-menu-admin"
          @open="handleOpen"
          @close="handleClose"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b">
          <!-- <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>系统基础管理</span>
            </template>
            <el-submenu index="1-1">
              <template slot="title">
                 <i class="el-icon-location"></i>
                 <span>用户管理</span>
              </template>
              <el-menu-item index="/user">
                 <i class="el-icon-caret-right"></i>
                 <span slot="title">用户列表</span>
              </el-menu-item>
              <el-menu-item index="/role">
                 <i class="el-icon-caret-right"></i>
                 <span slot="title">角色管理</span>
              </el-menu-item>
            </el-submenu>
            <el-submenu index="1-2">
              <template slot="title">
                 <i class="el-icon-location"></i>
                 <span>基础设置</span>
              </template>
              <el-menu-item index="/org">
                 <i class="el-icon-caret-right"></i>
                 <span slot="title">组织架构管理</span>
              </el-menu-item>
            </el-submenu>
              <el-submenu index="1-3">
              <template slot="title">
                 <i class="el-icon-location"></i>
                 <span>系统设置</span>
              </template>
              <el-menu-item index="/menu">
                 <i class="el-icon-caret-right"></i>
                 <span slot="title">菜单管理</span>
              </el-menu-item>
            </el-submenu>
          </el-submenu> -->
           <el-submenu :index="item.id" v-for="item in menuData" :key="item.id">
              <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.text}}</span>
              </template>
              <template v-for="tag in item.nodes" >
              <el-submenu :index="tag.id" :key="tag.id" v-if="tag.nodes!=null">
                  <template slot="title" >
                  <i class="el-icon-location"></i>
                  <span>{{tag.text}}</span>
                  </template>
                  <el-menu-item :index="third.url" v-for="third in tag.nodes" :key="third.id">
                  <i class="el-icon-menu"></i>
                  <span slot="title">{{third.text}}</span>
                  </el-menu-item>
              </el-submenu>
              <el-menu-item :index="tag.url"  :key="tag.id" v-else>
              <i class="el-icon-menu"></i>
              <span slot="title">{{tag.text}}</span>
              </el-menu-item>
              </template>
           </el-submenu>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-container>
        <!--header 部门 -->
        <el-header>
          <i class="myicon myicon-menu toggle-btn" @click="toggleCollapse"></i>
          <div class="system-title">天津市津沽污水处理厂生产管理系统</div>
          <div>
            <span class="welcome">
              您好，{{$store.getters.username}}
            </span>
            <el-button type="text" @click="logOut">退出</el-button>
          </div>
        </el-header>
        <!-- 中间内容-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
    </div>
</template>
<script>
export default {
  data () {
    return {
      isCollapse: false,
      menuData: []
    }
  },
  created () {
    this.menuData = this.$store.getters.usermenu
  },
  methods: {
    handleOpen (key, keyPath) {},
    handleClose (key, keyPath) {},
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    },
    logOut () {
      // 清除登录状态
      localStorage.removeItem('mytoken')
      localStorage.removeItem('username')
      this.$router.push({ name: 'Login' })
    }
  }
}
</script>

<style lang="scss" scoped>
.home {
  height: 100%;
  .el-menu-admin:not(.el-menu--collapse) {
    width: 250px;
    min-height: 400px;
  }
  .el-menu-admin > li:last-child {
    margin-bottom: 50px;
  }
  .el-container {
    height: 100%;
  }
  .el-aside {
    background-color: #545c64;
  }
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #545c64;
  }
  .logo {
    height: 60px;
    display: block;
    background: url(../assets/logo.png);
    background-size: contain;
    background-repeat: no-repeat;
    // background-color: #989898;
    background-position: 0px 10px;
  }
  .toggle-btn {
    font-size: 36px;
    color: #989898;
    cursor: pointer;
    line-height: 60px;
  }
  .system-title {
    font-size: 28px;
    color: white;
  }
  .welcome {
    color: white;
  }
}
</style>
